//
//  HHPropertyTableViewCell.m
//  HHBroker
//
//  Created by He Wei on 9/19/15.
//  Copyright © 2015 harry. All rights reserved.
//

#import "HHPropertyTableViewCell.h"
//#import "HHInputAccessoryView.h"
@interface HHPropertyTableViewCell () <UITextFieldDelegate>


@end
@implementation HHPropertyTableViewCell

- (void)awakeFromNib {
    // Initialization code
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.separatorInset = UIEdgeInsetsMake(0, 105, 0, 0);
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setModel:(HHPropertyInfoModel *)model
{
    _model = model;
    [self changeLayout];
}
- (void)changeLayout
{
    self.titleLabel.text = _model.title;
    self.infoTextField.placeholder = _model.des;
    if (_model.value) {
        self.infoTextField.text = _model.value;
    }
    self.infoTextField.delegate = self;
    //self.infoTextField.inputAccessoryView = self.inputAccessoryView;
    switch (_model.inputType) {
        case 0:
        {
            self.infoTextField.keyboardType = UIKeyboardTypeDefault;
        }
            break;
        case 1:
        {
            //self.infoTextField.keyboardType = UIKeyboardTypeDefault;
        }
            break;
        case 2:
        {
            self.infoTextField.secureTextEntry = YES;
        }
            break;
        case 3:
        {
            self.infoTextField.keyboardType = UIKeyboardTypeASCIICapable;
        }
            break;
        case 4:
        {
            self.infoTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
        }
            break;
        default:
            break;
    }
    
}

#pragma mark -Delegate
#pragma mark -UITextFieldDelegate

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(HHPropertyTableViewCell:didBeginEditingWithIndexPath:type:tag:)]) {
        [self.delegate HHPropertyTableViewCell:self didBeginEditingWithIndexPath:self.indexPath type:_model.inputType tag:_model.tag];
    }
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if ([self.delegate respondsToSelector:@selector(HHPropertyTableViewCell:completeResponseWithIndexPath:)]) {
        [self.delegate HHPropertyTableViewCell:self completeResponseWithIndexPath:self.indexPath];
    }
}

#pragma mark - Event
- (void)lastButtonClicked:(UIButton *)button
{
    if ([self.delegate respondsToSelector:@selector(HHPropertyTableViewCell:selectLastResponseWithIndexPath:)]) {
        [self.delegate HHPropertyTableViewCell:self selectLastResponseWithIndexPath:self.indexPath];
    }

}

- (void)nextButtonClicked:(UIButton *)button
{
    if ([self.delegate respondsToSelector:@selector(HHPropertyTableViewCell:selectNextResponseWithIndexPath:)]) {
        [self.delegate HHPropertyTableViewCell:self selectNextResponseWithIndexPath:self.indexPath];
    }
}

- (void)completeButtonClicked:(UIButton *)button
{
    if ([self.delegate respondsToSelector:@selector(HHPropertyTableViewCell:completeResponseWithIndexPath:)]) {
        [self.delegate HHPropertyTableViewCell:self completeResponseWithIndexPath:self.indexPath];
    }
}



#pragma mark - Setter && Getter

//- (JYInputAccessoryView *)inputAccessoryView
//{
//    if (_inputAccessoryView == nil) {
//        _inputAccessoryView = [JYInputAccessoryView inputAccessoryView];
//        if (self.isFirst) {
//            _inputAccessoryView.lastButton.enabled = NO;
//        }
//        if (self.isLast) {
//            _inputAccessoryView.nextButton.enabled = NO;
//        }
//        [_inputAccessoryView.lastButton addTarget:self action:@selector(lastButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
//        [_inputAccessoryView.nextButton addTarget:self action:@selector(nextButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
//        [_inputAccessoryView.completeButton addTarget:self action:@selector(completeButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
//        
//    }
//    return _inputAccessoryView;
//}


@end
